import {createRouter, createWebHistory} from 'vue-router'


const routes = [
    {
        path: '/login',
        name: '登录',
        meta: {title: '登录 | Preserved Blog'},
        // route level code-splitting
        // this generates a separate chunk (about.[hash].js) for this route
        // which is lazy-loaded when the route is visited.
        component: () => import(/* webpackChunkName: "login" */ '../views/Login.vue')
    },
    {
        path: '/register',
        name: '注册',
        meta: {title: '注册 | Preserved Blog'},
        component: () => import('../views/Register')
    },
    {
        path: '/retrieve',
        name: '找回密码',
        meta: {title: '找回密码 | Preserved Blog'},
        component: () => import('../views/Retrieve')
    },
    {
        path: '/changePhone',
        name: '改绑手机号',
        meta: {title: '改绑手机号 | Preserved Blog'},
        component: () => import('../views/ChangePhone')
    },
    {
        path: '/',
        name: '首页',
        meta: {title: '主页 | Preserved Blog'},
        component: () => import('../views/Blog'),
        children: [
            {
                path: '/',
                name: 'Preserved小栈',
                meta: {title: '首页 | Preserved Blog'},
                component: () => import('../page/Homepage')
            },
            {
                path: 'blog/article',
                name: '热门博客',
                meta: {title: '博客 | Preserved Blog'},
                component: () => import('../page/article')
            },
            {
                path: 'blog/message',
                name: '留言板',
                meta: {title: '留言 | Preserved Blog'},
                component: () => import('../page/Message')
            },
            {
                path: 'blog/album',
                name: '相册集',
                meta: {title: '相册 | Preserved Blog'},
                component: () => import('../page/Album')
            },
            {
                path: 'blog/personal',
                name: '个人中心',
                meta: {title: '个人中心 | Preserved Blog'},
                component: () => import('../page/Personal')
            },
            {
                path: 'blog/aetails/:id',
                name: '文章详情',
                meta: {title: '文章详情 | Preserved Blog'},
                component: () => import('../page/Aetails')
            },
            {
                path: 'blog/create',
                name: '撰写文章',
                meta: {title: '撰写文章 | Preserved Blog'},
                component: () => import('../page/Create')
            },
            {
                path: 'blog/friend',
                name: '友情链接',
                meta: {title: '友链 | Preserved Blog'},
                component: () => import('../page/Friend')
            },
            {
                path: 'blog/about',
                name: '关于',
                meta: {title: '关于 | Preserved Blog'},
                component: () => import('../page/About')
            },
            {
                path: 'blog/label',
                name: '标签',
                meta: {title: '标签 | Preserved Blog'},
                component: () => import('../page/Label')
            },
            {
                path: 'blog/labels/:id',
                name: '标签详情',
                meta: {title: '标签详情 | Preserved Blog'},
                component: () => import('../page/LabelPage')
            },
            {
                path: 'blog/backstage',
                name: '后台管理',
                meta: {title: '后台管理 | Preserved Blog'},
                component: () => import('../page/Backstage')
            },

        ]
    },
    {
        path: '/NotFound',
        name: 'NotFound',
        meta: {title: 'Page not found | Preserved Blog'},
        component: () => import('../page/NotFound')
    },
    {
        path: "/:pathMatch(.*)",
        redirect: 'NotFound',
    }
]

const router = createRouter({
    history: createWebHistory(process.env.BASE_URL),
    routes
})

// eslint-disable-next-line no-unused-vars
// router.afterEach((to, form) => {
//     window.scrollTo(0, 0)
// })

export default router
